--[[
存入1000*次数金币，每10秒获得40x次数金币金币

金库被摧毁 本金连同利息消失
取出本金需要10秒操作
]]

ac.skill('存入金币'){
    tip = [[存入|cffffff00'get_gold'|r金币，每|cff00ff0010|r秒获得|cff00ff00'interest'|r金币|n|n|cff999999超高利率！存的越多收获越多，带你的亲朋一起来存吧|r]],
    count = 1,
    get_gold = function(self)
        return self.count * 1000
    end,
    interest = function(self)
        return math.ceil(self:get_gold()*0.04)
    end,
    on_add = function(self)
        local unit = self.owner
        local player = unit.owner
        unit_add_life2(unit,2)
        unit:set('生命上限',50)
        unit:set('生命恢复',0.2)
        unit.shop_title = ('当前存款：%s'):format(self.sum_gold)
        self:gc(unit:event '单位-伤害结算前'(function(_,_,target,data)
            data.current_damage = 1
            player:send_msg('|cffff0000金矿受到攻击！！！|r')
        end))
        self:gc(ac.loop(10 * 1000,function()
            if self.ex_gold>0 then
                player:add_icon('金币',self.ex_gold,unit)
            end
            if self.sum_gold>=1000000 and math.random(100)<=10 then
                player:send_msg('风声紧!扯呼!')
                unit:remove()
                return
            end
        end))
        self:gc(player:event '玩家-增加存款'(function(_,player,gold)
            self.sum_gold = math.ceil(self.sum_gold + gold)
            self.ex_gold = self.sum_gold * 0.04
            player:set_data('存款',self.sum_gold)
            unit.shop_title = ('当前存款：%s'):format(self.sum_gold)
        end))
        self:gc(player:event '玩家-取回本金'(function()
            local gold = self.sum_gold * math.random(30,70)/100
            player:notify('玩家-增加存款',player,-self.sum_gold)
            player:add_icon('金币',gold,unit)
            player:send_msg(('取回本金:|cff00ff00%0.0f|r'):format(gold))
            if gold>=1000000 then
                player:send_msg('开不下去了，溜了！溜了！')
                unit:remove()
            end
        end))
        self:gc(unit:event '单位-拦截死亡'(function(trg)
            local gold = player:get_data('存款',0)
            player:notify('玩家-增加存款',player,-gold)
            unit:add_buff '假死复活'{time = unit:get '复活时间'}
            return true
        end))
    end,
    ex_gold = 0,
    sum_gold = 0,
    on_sell = function(self,hero,player)
        local unit = self.owner
        local gold = self:get_gold()
        self.count = self.count + 1
        player:notify('玩家-增加存款',player,gold)
        show_skill_tip(player,self,'刷新')
    end
}

ac.skill('取出本金'){
    tip = [[因为资金流通问题，只能拿回30%~70%的金币|n办理手续需要10秒时间|n|n|cff999999大侠别这样啊！|r]],
    cool = 10,
    on_sell = function(self,hero,player)
        local unit = self.owner
        if unit['操作中'] then
            player:send_msg('正在执行操作中')
            self:set_cd(0)
            return
        end
        local gold = player:get_data('存款',0)
        if gold==0 then
            player:send_msg('没有存款！')
            self:set_cd(0)
            return
        end
        unit['操作中'] = true
        unit:add_buff '取出本金'{
            time = 10,
            progress_type = -1,
            on_remove = function()
                unit['操作中'] = nil
                show_skill_tip(player,self,'刷新')
                player:notify('玩家-取回本金',player)
            end
        }
    end,
}



ac.skill('玩杠杆'){
    tip = [[需求：|n - 存款至少|cffffff0010000|r|n|n说明：|n - 使用|cff00ff0050%|r存款去玩杠杆，10秒后获得|cff00ff000%|r~|cffff0000200%|r收益|n|n|cff999999哥信我的稳赚不赔！|r]],
    cool = 60,
    on_sell = function(self,hero,player)
        local unit = self.owner
        local gold = player:get_data('存款',0)
        if gold<10000 then
            player:send_msg('存款不够！')
            self:set_cd(0)
            return
        end
        if unit['操作中'] then
            player:send_msg('正在执行操作中')
            self:set_cd(0)
            return
        end
        unit['操作中'] = true
        local gold = gold * 0.5
        player:notify('玩家-增加存款',player,-gold)
        unit:add_buff '玩杠杆'{
            time = 10,
            progress_type = -1,
            on_remove = function()
                local rate = math.random(0,20)*10
                local gold = gold * rate/100
                unit['操作中'] = nil
                player:notify('玩家-增加存款',player,gold)
                if rate>100 then
                    player:send_msg(('杠杆结果：获得%0.f存款(|cffff0000%0.0f%%|r)'):format(gold,rate))
                else
                    player:send_msg(('杠杆结果：获得%0.f存款(|cff00ff00%0.0f%%|r)'):format(gold,rate))
                end
            end
        }
    end,
}